
<?php

class AjaxController extends Base_Controller
{

    public function init()
    {
        parent::init();
    	$this->_helper->layout->disableLayout();
    }
    
    public function ajaxAction() {
    	$type = $_GET['type'];
    	if (strtoupper($type) == strtoupper("AllUserInfo")) {
    	 	$this->getAllUserInfo();
    	} else if (strtoupper($type) == strtoupper("AllBlogTitle")) {
    		isset($_GET['uid'])? $uid = $_GET['uid']:$uid=null;
    		$this->getAllBlog($uid);
    	} else if (strtoupper($type) == strtoupper("AllComments")) {
    		isset($_GET['uid'])? $uid = $_GET['uid']:$uid=null;
    		$this->getAllComments($uid);
    	}
		
    }

    private function getAllUserInfo() {
    	$userInfo = Application_Model_UserService::getInstance()->getAllUserInfo();
    	foreach ($userInfo as $user) {
    		echo "<a href='/?uid=".$user['uid']."'>".$user['nickname']."</a>&nbsp;&nbsp;";
    	}
    }
    
    private function getAllBlog($uid) {
    	$blogs = Application_Model_BlogService::getInstance()->getBlogTitle($uid);
    	foreach ($blogs as $blog) {
    		echo $blog['create_date']."&nbsp;<a href='/?uid=".$blog['uid']."'>".$blog['nickname']."</a>&nbsp"
    		." 发表了一篇博文 "
    		."&nbsp;<a href='/blog/view?blogId=".$blog['bid']."'>".$blog['title']."</a><br>";
    	}
    }
    private function getAllComments($uid) {
    	$comments = Application_Model_CommentService::getInstance()->getAllComments($uid);
    	foreach ($comments as $commnet) {
    		echo $commnet['create_date']."&nbsp;<a href='/?uid=".$commnet['comment_owner_id']."'>".$commnet['commnet_owner_nickname']."</a>&nbsp"
    		." 评论了博客 "
    		."&nbsp;<a href='/blog/view?blogId=".$commnet['content_id']."'>".$commnet['content_title']."</a><br>";
    	}
    } 
 
    public function getpositionAction()
    {
    	$entrepotId = $this->getRequest()->getParam('entrepotId');
    	$this->logger->debug("entrepotId  =    $entrepotId");
    	$mapper = new Application_Model_Dao_StockinMapper();
    	$this->view->position = $mapper->getPositionByEntrepotId($entrepotId);
//    	$this->view->steel = $mapper->getSteelByEntrepotId($entrepotId);
    	$this->view->steelInfo = json_encode($mapper->getSteelByEntrepotId($entrepotId));
    }
    
    public function get_product_by_entrepot_idAction() {
    	$entrepotId = $this->getRequest()->getParam('entrepotId');
    	
    }
	
	public function jsoninfoAction(){
		$info = $this->getRequest()->getParam('info');
		if ($info == "all_blogs") {
			$blogService = new Application_Model_BlogService();
			$blogs = $blogService->fetchAll();
			
			$json = "{blogs:[";
			for ($i=0; $i<sizeof($blogs); $i++) {
				if($i != 0) {
					$json = $json . ",";
				}
				$json = $json . "{";
				$json = $json . "title:\"". $blogs[$i]->getTitle() . "\"";
				$json = $json . ",content:\"". $blogs[$i]->getContent() . "\"";
				
				
				$json = $json . "}"; 
			}
			$json = $json . "]}";
			
			
			$this->view->jsoninfo=$json;
		}
		
		
		//$this->view->blogs=json_encode($blogs);
//		$json = "{blogs:[";
//		for ($i=0; $i<sizeof($blogs); $i++) {
//			if($i != 0) {
//				$json = $json . ",";
//			}
//			$json = $json . "{";
//			$json = $json . "title:\"". $blogs[$i]->getTitle() . "\"";
//			$json = $json . ",content:\"". $blogs[$i]->getContent() . "\"";
//			
//			
//			$json = $json . "}"; 
//		}
//		$json = $json . "]}";
//		$this->logger->debug($json);
//		$this->view->data='{title:"",content:"s"}';
	}

}
class Test {
	public $a = "222222222";
	public function getA() {
		return $this->a;
	}
}